package org.example.dev.learn;

import org.example.dev.learn.bean.Student;
import org.example.dev.learn.util.JsonUtil;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        System.out.printf("ok");
        testMap();
    }

    public static void testJsonUtil() {
        Map<String, Object> map = new HashMap<String, Object>();
        Student student = new Student("张三", 12);
        map.put("key1", 1);
        map.put("key2", "23");

        Map<String, Object> mapw = new HashMap<>();
        mapw.put("student", student);
        mapw.put("list", Arrays.asList("212","3333fffmm"));

        map.put("mapw", mapw);
        String json = JsonUtil.toJson(map);
        Map<String, Object> m = JsonUtil.json2map(json);


        Map<String, Object> sss = JsonUtil.json2map(JsonUtil.toJson(m.get("mapw")));




        System.out.println(JsonUtil.toJson(sss.get("student")));

    }

    public static void testMap() {
// 初始化Map对象
        Map<String, List<String>> map = new HashMap<>();

        // 要添加的key和value
        String key = "exampleKey";
        String valueToAdd = "exampleValue";

        // 使用computeIfAbsent方法来添加元素
        map.computeIfAbsent(key, k -> new ArrayList<>()).add(valueToAdd);

        // 打印Map的内容
        System.out.println(map);
    }

}
